package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SuperOrderItem;
import com.ruoyi.system.service.ISuperOrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单明细:记录每个订单的商品详情Controller
 * 
 * @author ruoyi
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/order/item")
public class    SuperOrderItemController extends BaseController
{
    @Autowired
    private ISuperOrderItemService superOrderItemService;

    /**
     * 查询订单明细:记录每个订单的商品详情列表
     */
    @PreAuthorize("@ss.hasPermi('order:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(SuperOrderItem superOrderItem)
    {
        startPage();
        List<SuperOrderItem> list = superOrderItemService.selectSuperOrderItemList(superOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出订单明细:记录每个订单的商品详情列表
     */
    @PreAuthorize("@ss.hasPermi('order:item:export')")
    @Log(title = "订单明细:记录每个订单的商品详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SuperOrderItem superOrderItem)
    {
        List<SuperOrderItem> list = superOrderItemService.selectSuperOrderItemList(superOrderItem);
        ExcelUtil<SuperOrderItem> util = new ExcelUtil<SuperOrderItem>(SuperOrderItem.class);
        util.exportExcel(response, list, "订单明细:记录每个订单的商品详情数据");
    }

    /**
     * 获取订单明细:记录每个订单的商品详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(superOrderItemService.selectSuperOrderItemById(id));
    }

    /**
     * 新增订单明细:记录每个订单的商品详情
     */
    @PreAuthorize("@ss.hasPermi('order:item:add')")
    @Log(title = "订单明细:记录每个订单的商品详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SuperOrderItem superOrderItem)
    {
        return toAjax(superOrderItemService.insertSuperOrderItem(superOrderItem));
    }

    /**
     * 修改订单明细:记录每个订单的商品详情
     */
    @PreAuthorize("@ss.hasPermi('order:item:edit')")
    @Log(title = "订单明细:记录每个订单的商品详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SuperOrderItem superOrderItem)
    {
        return toAjax(superOrderItemService.updateSuperOrderItem(superOrderItem));
    }

    /**
     * 删除订单明细:记录每个订单的商品详情
     */
    @PreAuthorize("@ss.hasPermi('order:item:remove')")
    @Log(title = "订单明细:记录每个订单的商品详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(superOrderItemService.deleteSuperOrderItemByIds(ids));
    }
}
